#include <bits/stdc++.h>
#define ll long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

inline static int read(){
    int sum=0,neg=0,ch=getchar();
    while(!isdigit(ch)) neg|=(ch=='-'),ch=getchar();
    while(isdigit(ch)) sum=sum*10+(ch^48),ch=getchar();
    return neg?-sum:sum;
}

// 对不起我是憨批
constexpr int mod=998244353,inf=1e9;
struct{ll x; int val;}s0[400005],s1[400005]; int a[200005],b[200005];
signed main(){
    freopen("b.in","r",stdin);
    freopen("b.out","w",stdout);
    s0->val=INT_MAX; ll ans;
    for(int T=1,n;T;printf("%lld\n",ans<0?ans+mod:ans),T--){
        n=read(),ans=0;
        for(int i=1;i<=n;i++) a[i]=read();
        for(int i=1;i<=n;i++) b[i]=read();
        s0[1]={b[1],a[1]},ans=(ll)a[1]*b[1]%mod;
        for(int i=2,t0=1,t1,L;i<=n;i++){
            L=read(),t1=0; ll sum=0;
            if(L!=1){
                for(int y=0;t0;t0--){
                    ll x=s0[t0].x;
                    if(y){
                        int t=min((ll)y,x); x-=t,y-=t,sum+=t*s0[t0].val;
                        if(sum>=inf) break; if(!y) s1[++t1]={1,(int)sum},sum=0;
                    }
                    if(x){
                        sum=(ll)s0[t0].val*L; if(sum>=inf) break; s1[++t1]={x/L,(int)sum};
                        int t=x-s1[t1].x*L; if(t) sum=(ll)s0[t0].val*t,y=L-t;
                    }
                } for(int j=1,k=t1;j<=t1;j++,k--) s0[j]=s1[k]; t0=t1;
            }
            for(sum=b[i];s0[t0].val<a[i];t0--)
                sum+=s0[t0].x,ans=(ans-s0[t0].x%mod*s0[t0].val)%mod;
            ans=(ans+sum*a[i])%mod,s0[++t0]={sum,a[i]};
        }
    } return 0;
}